package string;
public class StringDemo {
    public static void main(String[] args) {
        String s1 = "123abc";
        System.out.println(s1);
        String s2 = "123abc";
        System.out.println(s1==s2);
        String s3 = "123abc";
        System.out.println(s1==s3);

        String s4 = new String("123abc");//new会创建新的对象
        System.out.println(s1==s4);

        s1 += "!";//修改内容创建新的对象
        System.out.println(s1==s2);

        String s5 = "123" + "abc";//触发编译器预计算特性，直接编译为
        //String s5 = "123abc";JVM会复用该对象
        System.out.println(s5==s2);

        String s6 = "123";
        String s7 = s6 + "abc";//拼接字符串会产生新对象
        System.out.println(s7==s2);
        //==是比较值相等，引用中保存的是地址，所以==比较的也是地址
        String s8 = "114514";
        String s9 = new String("114514");
        System.out.println(s8.equals(s9));//比较内容
    }
}
